import { PayloadAction, createSlice } from "@reduxjs/toolkit";
import API from '@/api'
import { IBillItem } from "@/types/billList";

interface IInitialState {
  billList: Array<IBillItem>
}
const initialState: IInitialState = {
  billList: []
}
const billListStore = createSlice({
  name: 'billList',
  initialState,
  reducers: {
    setBillList(state, action: PayloadAction<Array<IBillItem>>) {
      state.billList = action.payload
    }
  }
})

export const { setBillList } = billListStore.actions;

export const getBillList = async () => {
  const res = await API.billList.getMonthPageList();
  setBillList(res.data.records);
}

export default billListStore.reducer;